import { Button, Space, message, Modal } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { WorkflowHndTaskBtn } from '@/components/WorkflowCommonCopy';
import { getTenantID, getUserID, printerPDF } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
// import { StampContractModal } from './StampContractModal';
import { history } from 'umi';
import { BGflowBusinessType } from '../common/Format';

export const DetailInfoViewBottomBtn: React.FC<any> = ({ detailInfo, position, changeRevoke, handleSave, getDetailRun, locationProps }) => {
  /** 申请页ref */
  const { confirm } = Modal;

  const closeCurrent = () => {
    confirm({
      title: '关闭',
      icon: <QuestionCircleOutlined />,
      content: '确定要关闭当前页吗？',
      okText: '确定',
      okType: 'primary',
      cancelText: '取消',
      onOk() {
        history.push({
          pathname: locationProps?.state?.returnPathName,
          state: {
            delRouterNameSource: history.location.pathname, //必传,要删除的路由名称
            returnPathName: locationProps?.state?.returnPathName,
          },
        });
      },
      onCancel() {},
    });
  };

  return (
    <>
      <div className="tabsBodyBottomBtn">
        <Space>
          {(locationProps?.state?.pageType !== 'detail' &&
            ((detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001` &&
              detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003`) ||
              (detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1000` && !detailInfo?.checkState)) &&
            detailInfo?.createrID == getUserID()) ||
          locationProps?.state?.pageType === 'add' ? (
            <Button
              type={'primary'}
              // icon={<SaveOutlined />}
              onClick={() => handleSave(false)}
            >
              暂存
            </Button>
          ) : null}

          {detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1002` ? (
            <Button
              type={'primary'}
              onClick={() => {
                message.success('执行中，请稍后...');
                printerPDF(detailInfo?.workflowURL);
              }}
            >
              打印
            </Button>
          ) : null}

          {position == 'top' &&
          (!detailInfo?.state ||
            (detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll?.STORAGE_TRANS_STATUS}1000` &&
              !detailInfo?.checkState &&
              detailInfo?.createrID == getUserID())) ? (
            <Button
              type={'primary'}
              // icon={<CheckCircleOutlined />}
              onClick={() => handleSave(true)}
            >
              提交
            </Button>
          ) : null}

          {position == 'top' && (
            <Button danger onClick={closeCurrent}>
              关闭
            </Button>
          )}

          {/* 流程节点弹框 */}
          {position == 'top' && (
            <WorkflowHndTaskBtn
              flowDetailInfo={detailInfo}
              reloadCallback={() => {
                getDetailRun(detailInfo?.id);
              }}
              requestController={'assetApplyAllot'}
              flowBusinessType={BGflowBusinessType()}
              isAloneSubmit={
                detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003` &&
                detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001`
              }
              applyHeader={'own'}
              revokeRequestUrl={'/assetApplyAllot/revoke'}
              revokeRequestState={`${getTenantID()}${ILoadMapTypeAll?.STORAGE_TRANS_STATUS}`}
              isShowRevokeStateList={[`${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001`]}
              revokeTitle={detailInfo?.applyTitle}
              revokeSuccessCallback={() => {
                history.push({
                  pathname: locationProps?.state?.returnPathName,
                  state: {
                    delRouterNameSource: history.location.pathname, //必传,要删除的路由名称
                    returnPathName: locationProps?.state?.returnPathName,
                  },
                });
              }}
              revokeReqBody={{
                massetListIds: detailInfo?.massetApplyNumberList?.map((item) => item?.materialOrAssetId)?.toString(','),
                massetListState:
                  detailInfo?.allotType == 1 || detailInfo?.allotType == 2
                    ? `${getTenantID()}${ILoadMapTypeAll.ASSET_STATUS}1000`
                    : detailInfo?.allotType == 3
                    ? `${getTenantID()}${ILoadMapTypeAll.ASSET_STATUS}1001`
                    : `${getTenantID()}${ILoadMapTypeAll.ASSET_STATUS}1001`,
              }}
            />
          )}

          {/* {detailInfo?.createrID == getUserID() &&
            ((detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1000` &&
              detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001`) ||
              (detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003` &&
                detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANS_STATUS}1001`)) && (
              <Button
                type={'primary'}
                danger
                onClick={() => {
                  changeRevoke();
                }}
              >
                撤销
              </Button>
            )} */}
        </Space>
      </div>
    </>
  );
};
